package com.youkeda.yunmusic.web.control;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

@Controller
public class MusicControl {
    //定义一个存放歌曲id和url的数组
    private static final Map<String,String>musics=new HashMap<>();
    @RequestMapping(value = "/song/music")
    @ResponseBody
    public String getMusicSrc(String songId){
        System.out.println("运行MUsicControl中的getMusic函数");
        //返回播放地址
        return musics.get(songId);
    }
    @PostConstruct//使这个方法在类初始化的时候自动执行
    public void init(){
        System.out.println("运行MUsicControl中的init函数");
        //对应的属性是songid和url地址.put()方法将隔壁musics赋值
        //去年夏天
        musics.put("557581476",
                "https://music.163.com/song/media/outer/url?id=557581476.mp3");

        //撒野
        musics.put("483937795",
                "https://music.163.com/song/media/outer/url?id=483937795.mp3");

    }
}
